package com.qf;

import lombok.SneakyThrows;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Test;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Random;

public class RandomNum {
    @SneakyThrows
    @Test
    public void writeToTxt(){
        String path = "/Users/manchi520/Desktop/qianfeng/Java-Mybatis/homework_0623/src/main/resources/Books.txt";
        BufferedWriter bw = new BufferedWriter(new FileWriter(path,true));

        for (int m = 0; m < 500000; m ++){
            for (int i = 0; i < 4; i ++){
                //随机生成指定长度的字母和数字的随机组合字符串
                String s = RandomStringUtils.randomAlphanumeric(10);
                if (i == 3){
                    //随机生成数字字符串
                    String numeric = RandomStringUtils.randomNumeric(1);
                    bw.write(numeric + "\n");
                }else {
                    bw.write(s + ",");
                }
            }
        }
        bw.close();
    }
}
